import commonData from "./data"
import httpUtil from "../utils/httpUtil"
import messageUtil from "../utils/messageUtil"


const currentVersion = 7;

function isAudit(successHandler, errHandler) {
  let params = {
    pid: 4,
    ver: currentVersion
  }

  httpUtil.post("/api/Alipayad/shenhe", params, res => {
    if (successHandler) {
      successHandler(res.data.is)
    }

  }, err => {
    if (errHandler) {
      errHandler(err)
    }
  })
}
 

function initOpenid() {
  // 页面加载
  my.getAuthCode({
    scopes: ['auth_base'],
    // 主动授权：auth_user，静默授权：auth_base或者其它scope。如需同时获取用户多项授权，可在 scopes 中传入多个 scope 值。
    success: (res) => {
      console.log('getAuthCode', res)
      if (!res.authCode) {
        return
      }

      let params = {
        code: res.authCode,
        type: 2,
        // appid: my.getParentAppIdSync().appId,
        appid:commonData.getAppid()
      }

      httpUtil.post('/api/hfmp/wxLogincj',params, res => {
        console.log('wxLogincj success', res)
      }, err => {
        console.log('wxLogincj err', err)
      })

    },
  });
}

module.exports = {
  initOpenid: initOpenid,
  currentVersion:currentVersion,
  isAudit:isAudit,
}